package com.cxs.observer.simple;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: cxs
 */
public class MainSubject {

    // 存放所有的观察者对象
    private List<ObServer> obServers = new ArrayList<>();

    private Double price;


    public void addObserver(ObServer obServer) {
        this.obServers.add(obServer);
    }

    public Double getPrice() {
        return price;
    }

    // 这个就是发生变化时的通知
    public void setPrice(Double price) {
        this.price = price;
        this.notifyAllOb();
    }

    public void notifyAllOb() {
        for (ObServer obServer : obServers) {
            obServer.doUpdate();
        }
    }
}
